import { defineStore } from 'pinia'

const useGuideStore = defineStore('guide', {
    state: () => {
        return {
            guideConfig: getGuide()
        }
    },
    actions: {
        addPage(pageNames: string | Array<string>) {
            if (Array.isArray(pageNames)) {
                pageNames.forEach((item:string)=>{
                    this.guideConfig.add(item)
                })
            }
            if (typeof pageNames == 'string') {
                this.guideConfig.add(pageNames)
            }
        }
    }
})

function getGuide(): Set<string> {
    let arr = uni.getStorageSync('guideSet')
    return new Set(arr)
}

function saveGuide(set: Set<string>) {
    uni.setStorageSync('guideSet', set)
}

export default useGuideStore
